package com.sjzsqjy.asdtiang.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ListPageQueryAction extends ActionSupport{
	private List<?> list;
	private int pageNow = 1; // 
	private int pageSize = 10; // 
	private int pageTotle = 1;// 
	private String hql;


	public ListPageQueryAction() {

	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public int getPageNow() {
		return pageNow;
	}

	public void setPageNow(int pageNow) {
		this.pageNow = pageNow;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageTotle() {
		return pageTotle;
	}

	public void setPageTotle(int pageTotle) {
		this.pageTotle = pageTotle;
	}

	@Override
	/**
	 * 会员登录后台时已经把景点列表放到session中
	 * pageNow当前页面序号
	 * pageSize每页显示的数据条数
	 * pageTotle分页后的页面总数
	 */
	public String execute() throws Exception {	
		//取出景点列表
		List l = (List) ActionContext.getContext().getSession().get("list");
		String view=(String) ActionContext.getContext().getSession().get("view");
		
		int i = l.size();
		if(i<pageNow * pageSize){
		    list = l.subList(pageNow * pageSize - pageSize, i);
		}
		else{
			list = l.subList(pageNow * pageSize - pageSize, pageNow * pageSize);
		}
		pageTotle = i % pageSize == 0 ? i / pageSize : i / pageSize + 1;
		return view;
	}

}
